<template>
  <h1>信息</h1>
  <h2>姓名：{{ person.name }}</h2>
  <h2>年龄：{{ person.age }}</h2>
  <button @click="test">测试一下</button>
</template>

<script>
import { ref, reactive } from "vue";
export default {
  name: "Demo",
  props: ["msg", "school"],
  // Vue3自定义事件也需要接收
  emits: ["hello"],
  beforeCreate() {
    console.log("--beforeCreate--");
  },
  setup(props, context) {
    console.log("--setup--", this);
    console.log(props, context);
    console.log(context.slots);
    /* 
        this是undefined，所以在setup里this无法使用
    */
    let person = reactive({
      name: "张三",
      age: 18,
      job: {
        type: "技术占",
        salary: "20k",
      },
      hobby: ["跑步", "代码", "摄影"],
    });
    function test() {
      context.emit("hello", 555);
    }

    return {
      person,
      test,
    };
  },
};
</script>

<style>
</style>
